<?php

class femaleAuth
{
    private $apiurl;
    private $apis;
    private $action;
    private $uuid   = 0;
    private $status = 0;//通过
    private $start  = 0;
    private $length = 20;
    
    public function __construct() {
    	global $_SC;
    	$this->apiurl   = $_SC['apiurl'];
        $this->apis     = array(
            'permit','reapply','getFemaleAuthList','getUserFemaleAuthInfo'
        );
    }
    
    public function execute ($action) {
        if (empty($action)) return false;
        if (!in_array($action, $this->apis)) return false;
        $this->action = $action;
        $result = $this->$action(request());
        return $result;
    }
    
    private function getFemaleAuthList($req){
    	$param = $this->filterArgumentsOfPassed($req);
    	
    	$result = requestApi($param);
    	
    	$mpurl 	 	= 'admin.php?ac=femaleAuth_class&op=getFemaleAuthList';
    	$start 	 	= $this->validateParam('start',$req);
    	$length  	= $this->validateParam('length',$req);
    	$pageurl 	= multi($start,$length, $mpurl);
    	$currentPage= $this->getCurrentPage($req,$start);
    	return render('femaleauth', array('list'=>$result['list'],'allNum'=>$result['totlecount'],'currentPage'=>$currentPage,'pageUrl'=>$pageurl));

    }
	private function getCurrentPage($req,$start){
		if($req['page'] && intval($req['page'])>0){
			return $req['page'];
		}
		return $start/($this->length)+1;
	}
    private function getUserFemaleAuthInfo($req){
    	$param = $this->filterArgumentsOfPassed($req);
    	$list = requestApi($param);
    	return render('femaleauth', array('list'=>$list));
    }
    
    private function permit($req){
    	$param = $this->filterArgumentsOfPassed($req);
    	$result = requestApi($param);
    	return json_encode($result);
    }
    
    private function reapply($req){
    	$param = $this->filterArgumentsOfPassed($req);
    	$result = requestApi($param);
    	return json_encode($result);
    }
    /**
     * 传参过滤
     * @param unknown $req
     * @return multitype:string number NULL
     */
    private function filterArgumentsOfPassed($req) {
        switch ($this->action){
            case 'permit':
            	$param=array(
            			'do'    => 'femaleAuth',
            			'action'=> 'permitFemaleAuth',
            			'format'=>'json',
            			'uuid'  => $this->validateParam('uuid',$req),
            			'status'=> $this->validateParam('status',$req),
            	);
                break;
            case 'reapply':
            	$param=array(
            			'do'    => 'femaleAuth',
            			'action'=> 'reapplyFemaleAuth',
            			'format'=>'json',
            			'uuid'  => $this->validateParam('uuid',$req),
            	);
                break;
            case 'getFemaleAuthList':
            	$param=array(
            			'do'     =>'femaleAuth',
            			'action' => 'getFemaleAuthList',
            			'status' => 1,
            			'uuid'   => 0,
            			'start'  => $this->validateParam('start',$req),
            			'length' => $this->validateParam('length',$req),
            			'format'=>'json'
            	);
            	if(!empty($req['page']) && intval($req['page'])>0){
            		$param['start'] = (intval($req['page'])-1)*($this->length);
            	}
                break;
            case 'getUserFemaleAuthInfo':
            	$param=array(
            			'do'     =>'femaleAuth',
            			'action' => 'getUserFemaleAuthInfo',
            			'uuid'  => $this->validateParam('uuid',$req),
            			'format'=>'json'
            	);
                break;
        }
        
        return $param;
    }
    private function pageUrl(){
    	
    }
    private function validateParam($paramStr,$req){
    	return empty($req[$paramStr]) ? $this->$paramStr : $req[$paramStr];
    }
    
}
//将对应状态码转换为中文含义
function interpretationState($status){
	$s=array(0,1,2,4);
	if(in_array($status, $s)){
		switch ($status) {
			case 0:
				echo '认证成功';
				break;
			case 1:
				echo '认证中';
				break;
			case 2:
				echo '拉黑';
				break;
			case 4:
				echo '申请失败';
				break;
		}
	}else{
		echo '未知';
	}
}
$req = request();
$femaleAuth   = new femaleAuth();
echo $femaleAuth->execute($req['op']);
exit();
